import axios from 'axios';
import { base_url } from '../config';

export const upload_excel = {
    /*
     * 查询某个用户的所有上传文件
     * 后续这个接口应该修改为：获取用户的文件目录树
     */
    getAllFiles() {
        return new Promise(async (resolve, reject) => {
            // let jwt = localStorage.getItem('jwt');
            let jwt = '';
            axios.get(base_url + '/upload_excel/getAllFiles', {
                headers: {
                    'Content-Type': 'application/json',
                    'Authorization': jwt
                }
            }).then((res) => {
                console.log('【 resposeData: in function getAllFiles 】', res);
                resolve(res.data);
            }).catch((err) => {
                console.log('【 err: in function getAllFiles 】', err);
                reject(err);
            });
        });
    },
    /*
     * 上传excel文件
     */
    uploadExcel(fileName, data) {
        return new Promise(async (resolve, reject) => {
            // let jwt = localStorage.getItem('jwt');
            let jwt = '';
            axios.post(base_url + '/upload_excel/uploadExcel', { fileName, data }, {
                headers: {
                    'Content-Type': 'application/json',
                    'Authorization': jwt
                }
            }).then((res) => {
                console.log('【 resposeData: in function uploadExcel 】', res);
                resolve(res.data);
            }).catch((err) => {
                console.log('【 err: in function uploadExcel 】', err);
                reject(err);
            });
        });
    },
    /*
     * 下载 excel 文件
     */
    downloadExcel(fileId) {
        return new Promise(async (resolve, reject) => {
            // let jwt = localStorage.getItem('jwt');
            let jwt = '';
            axios.post(base_url + '/upload_excel/downloadExcel', { fileId }, {
                headers: {
                    'Content-Type': 'application/json',
                    'Authorization': jwt
                }
            }).then((res) => {
                console.log('【 resposeData: in function downloadExcel 】', res);
                resolve(res.data);
            }).catch((err) => {
                console.log('【 err: in function downloadExcel 】', err);
                reject(err);
            });
        });
    },
    // 加载 二级事项
    loadSubItem(contentId) {
        return new Promise(async (resolve, reject) => {
            // let jwt = localStorage.getItem('jwt');
            let jwt = '';
            axios.post(base_url + '/upload_excel/loadSubItem', { contentId }, {
                headers: {
                    'Content-Type': 'application/json',
                    'Authorization': jwt
                }
            }).then((res) => {
                console.log('【 resposeData: in function loadSubItem 】', res);
                resolve(res.data);
            }).catch((err) => {
                console.log('【 err: in function loadSubItem 】', err);
                reject(err);
            });
        });
    },
}